﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using HigLabo.Net.Extensions;


namespace HigLabo.Net.Twitter
{
    /// <summary>
    /// 
    /// </summary>
    public class Configuration : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public Int32 CharactersReservedPerMedia { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 MaxMediaPerUpload { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public List<String> NonUsernamePaths { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int64 PhotoSizeLimit { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Sizes PhotoSizes { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 ShortUrlLengthHttps { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 ShortUrlLength { set; get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public Configuration(String jsonText)
        {
            this.SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(string jsonText)
        {
            var d = this.SetData(jsonText);

            this.CharactersReservedPerMedia = d.ToInt32("characters_reserved_per_media") ?? 0;
            this.MaxMediaPerUpload = d.ToInt32("max_media_per_upload") ?? 0;
            this.NonUsernamePaths = new List<string>();
            var cc = JsonConvert.DeserializeObject(d.ToString("non_username_paths")) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.NonUsernamePaths.Add(i.ToString());
                }
            }
            this.PhotoSizeLimit = d.ToInt64("photo_size_limit") ?? 0;
            this.PhotoSizes = new Sizes(d.ToString("photo_sizes"));
            this.ShortUrlLengthHttps = d.ToInt32("short_url_length_https") ?? 0;
            this.ShortUrlLength = d.ToInt32("short_url_length") ?? 0;
        }
    }
}
